const Router = require("koa-router");
const multer = require('koa-multer');
const user = require('./controller/user');

const upload = multer({ dest: 'uploads/' }); // 定义文件上传目录
const router = new Router();

router.get("/", ctx => {
  ctx.body = `这是主页`;
});

router.get("/user", ctx => {
  ctx.body = `这是user页`;
});

router.post("/user/login", user.login);

// 文件上传测试
router.post('/upload', upload.single('file'), async (ctx,next) =>  {
  console.log(ctx.req.file.originalname + ' -> ' + ctx.req.file.filename);
  ctx.response.body ="<h1>上传成功！</h1>";
});

module.exports = router;